package util

import (
	"fmt"
	"gitee.com/visons/gopkg/logger"
	"runtime/debug"
)

func Protect(f func()) {
	defer func() {
		if err := recover(); err != nil {
			stack := debug.Stack()
			fmt.Printf("%s", stack)
			fmt.Print(stack)
			logger.Error("%s %s", err, stack)
		}
	}()
	f()
}
